package com.struts2.example.action;

import java.sql.Connection;
import java.sql.PreparedStatement;

import com.opensymphony.xwork2.ActionSupport;
import com.struts2.example.model.Connect;

public class InsertAnswersAction extends ActionSupport{

	/**
	 * 
	 */
	private String TAG="InsertAnswersAction : ";
	private static final long serialVersionUID = 1L;
	private int questionIdBean;
	private String answer;
	private String typeAnswer;
	public String execute()
	{
		System.out.print(TAG+ getQuestionIdBean()+"\n");
		System.out.print(TAG+getAnswer()+"\n");
		String ret = ERROR;
		Connect conn = new Connect();
		Connection connected = conn.GetConnect();
		
		try {
			String sql = "insert into  testonline_bang_dai.answer values (default, ?, ?,?)";
			PreparedStatement ps = connected.prepareStatement(sql);
			ps.setString(1,String.valueOf(getQuestionIdBean()));
			ps.setString(2, getAnswer());
			ps.setString(3,getTypeAnswer());
			System.out.print(TAG+"typeAnswer :"+getTypeAnswer());
			ps.executeUpdate();
			ret =SUCCESS;
		} catch (Exception e) {
			ret = ERROR;
		} finally {
			if (connected != null) {
				try {
					connected.close();
				} catch (Exception e) {
				}
			}
		}
		return ret;
	}
	
	public int getQuestionIdBean()
	{
		return this.questionIdBean;
	}
	
	public void setQuestionIdBean(int questionIdBean)
	{
		this.questionIdBean=questionIdBean;
	}
	
	public String getAnswer()
	{
		return this.answer;
	}
	
	public void setAnswer(String answer)
	{
		this.answer=answer;
	}

	public String getTypeAnswer() {
		return typeAnswer;
	}

	public void setTypeAnswer(String typeAnswer) {
		this.typeAnswer = typeAnswer;
	}
	

}
